package cn.dengta.webapp.push.vo;

import java.io.Serializable;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.*;

@Getter
@Setter
@Accessors(chain = true)
public class YunxinFileVO implements Serializable {

	/** 图片name */
	private String name;
	/** 图片文件md5 */
	private String md5;
	/** 图片url */
	private String url;
	/** 图片后缀 */
	private String ext;
	/** 宽 */
	private Integer w;
	/** 高 */
	private Integer h;
	/** 图片文件大小 */
	private Integer size;
	/** 时长ms */
	private Long dur;

	/**
	 * 图片 数据载体
	 * {
	 * "name":"图片发送于2015-05-07 13:59",   //图片name
	 * "md5":"9894907e4ad9de4678091277509361f7",    //图片文件md5
	 * "url":"http://nimtest.nos.netease.com/cbc500e8-e19c-4b0f-834b-c32d4dc1075e",    //生成的url
	 * "ext":"jpg",    //图片后缀
	 * "w":6814,    //宽
	 * "h":2332,    //高
	 * "size":388245    //图片文件大小
	 * }
	 */
	public YunxinFileVO initImage(String name, String url) {
		this.name = name;
		this.md5 = Encrypter.md5(url);
		this.url = url;
		this.ext = FileUtil.getExtension(url, true);
		this.w = 150;
		this.h = 150;
		this.size = 15000;
		return this;
	}

	/**
	 * 语音载体数据
	 * {
	 * "dur":4551,		//语音持续时长ms
	 * "md5":"87b94a090dec5c58f242b7132a530a01",	//语音文件的md5值
	 * "url":"http://nimtest.nos.netease.com/a2583322-413d-4653-9a70-9cabdfc7f5f9",	//生成的url
	 * "ext":"aac",		//语音消息格式，只能是aac格式
	 * "size":16420		//语音文件大小
	 * }
	 */
	public YunxinFileVO initAudio(Long dur, String url) {
		this.dur = dur;
		this.md5 = Encrypter.md5(url);
		this.url = url;
		this.ext = FileUtil.getExtension(url, true);
		this.size = 15000;
		return this;
	}

	/**
	 * 视频载体数据
	 * {
	 * "dur":8003,	//视频持续时长ms
	 * "md5":"da2cef3e5663ee9c3547ef5d127f7e3e",	//视频文件的md5值
	 * "url":"http://nimtest.nos.netease.com/21f34447-e9ac-4871-91ad-d9f03af20412",	//生成的url
	 * "w":360,	//宽
	 * "h":480,	//高
	 * "ext":"mp4",	//视频格式
	 * "size":16420	//视频文件大小
	 * }
	 */
	public YunxinFileVO initVideo(Long dur, String url, Integer w, Integer h) {
		this.dur = X.expectNotNull(dur, 20000L);
		this.md5 = Encrypter.md5(url);
		this.url = url;
		this.ext = FileUtil.getExtension(url, true);
		this.w = X.expectNotNull(w, 360);
		this.h = X.expectNotNull(h, 480);
		this.size = 15000;
		return this;
	}

}
